# {{ ansible_managed }}

[Unit]
Description="{{ item.value.description | default("Service for " + item.key) }}"
{% if item.value.wants is defined %}
Wants={{ item.value.wants }}
{% endif -%}
{% if item.value.requires is defined %}
Requires={{ item.value.requires }}
{% endif -%}
{% if item.value.before is defined %}
Before={{ item.value.before }}
{% endif -%}
{% if item.value.after is defined %}
After={{ item.value.after }}
{% endif %}

[Service]
{% if item.value.type is defined %}
Type={{ item.value.type }}
{% endif -%}
{% if item.value.pid_file is defined %}
PIDFile={{ item.value.pid_file }}
{% endif -%}

{% if item.value.timeout_sec is defined %}
TimeoutSec={{ item.value.timeout_sec }}
{% endif -%}
{% if item.value.restart is defined %}
RestartSec={{ item.value.restart_sec | default('30') }}
Restart={{ item.value.restart }}
{% endif -%}

{% if item.value.environment is defined %}
{% for env in item.value.environment %}
Environment={{ env }}
{% endfor -%}
{% endif -%}
{% if item.value.environment_file is defined %}
EnvironmentFile={{ item.value.environment_file }}
{% endif -%}

{% if item.value.working_directory is defined %}
WorkingDirectory={{ item.value.working_directory }}
{% endif -%}
{% if item.value.user is defined %}
User={{ item.value.user }}
{% endif -%}
{% if item.value.group is defined %}
Group={{ item.value.group }}
{% endif -%}

{% if item.value.oom_score_adjust is defined %}
OOMScoreAdjust={{ item.value.oom_score_adjust }}
{% endif -%}
{% if item.value.nice is defined %}
Nice={{ item.value.nice }}
{% endif -%}

{% if item.value.exec_stop is defined %}
ExecStop={{ item.value.exec_stop }}
{% endif -%}
{% if item.value.exec_stop_post is defined %}
ExecStopPost={{ item.value.exec_stop_post }}
{% endif -%}
{% if item.value.exec_reload is defined %}
ExecReload={{ item.value.exec_reload }}
{% endif -%}

{% if item.value.exec_start_pre is defined %}
ExecStartPre={{ item.value.exec_start_pre }}
{% endif -%}
{% if item.value.exec_start_post is defined %}
ExecStartPost={{ item.value.exec_start_post }}
{% endif -%}
{% if item.value.exec_start is defined %}
ExecStart={{ item.value.exec_start }}
{% endif -%}

{% if item.value.standard_input is defined %}
StandardInput={{ item.value.standard_input }}
{% endif -%}
{% if item.value.standard_output is defined %}
StandardOutput={{ item.value.standard_output }}
{% endif -%}
{% if item.value.standard_error is defined %}
StandardError={{ item.value.standard_error }}
{% endif %}

[Install]
{% if item.value.wanted_by is defined %}
WantedBy={{ item.value.wanted_by }}
{% endif -%}
{% if item.value.required_by is defined %}
RequiredBy={{ item.value.required_by }}
{% endif %}
